<?php
include 'common/header.html';
include 'common/left.html';

$domain = 'http://www.12301.cc/';
if ($_SERVER['HTTP_HOST']!='www.12301.cc') {
    include("/var/www/html/new/d/class/SubDomain.php");
    $shop = SubDomain::SubDomainConf();
    $domain = "http://{$shop['M_domain']}.12301.cc/new/d/";
}
$sql_get_hash = "SELECT hash,ac_type FROM pft_wx WHERE fid={$_SESSION['memberID']} LIMIT 1";
$GLOBALS['le']->query($sql_get_hash);
if (!$GLOBALS['le']->fetch_assoc()) {
    exit('您还没有绑定公众号');
}
$hash    = $GLOBALS['le']->f('hash');
$ac_type = $GLOBALS['le']->f('ac_type');//公众号类型0订阅号1服务号

?>
    <link rel="stylesheet" href="http://www.12301.cc/css/aliceui.min.css"/>
    <style>
        .media_edit_area{position: relative;}
        #imgdiv{
            display: none;
            position: absolute;
            right: 4px;
            top: 100px;
        }
    </style>
    <script>
        function PreviewImage() {

            var oFReader = new FileReader();
            oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);

            oFReader.onload = function (oFREvent) {
                $("#imgdiv").show();
                document.getElementById("uploadPreview").src = oFREvent.target.result;
            };
        };

    </script>
    <div class="main_bd">
      <h3 class="wei_title">
         <span class="wxtit_1"><a href="weimsg_t.html"><span class="wxtit_2">文本消息</span></a></span>
         <span class="wxtit_1"><a href="weimsg_m.html"><span class="wxtit_3">图文消息</span></a></span>
      </h3>

        <div class="media_edit_area">
            <div id="imgdiv"><img id="uploadPreview" width="300" height="200" /></div>
            <form id="frm" class="ui-form"
                  method="post"
                  action="<?=$domain?>module/wechat/ichat.php"
                  enctype="multipart/form-data" target="hideFrame">
                <input name="hash" value="<?=$hash?>" type="hidden"/>
                <input name="action" value="SendMsg" type="hidden"/>
                <input name="ac_type" value="<?=$ac_type?>" type="hidden"/>
                <input name="msg_type" value="news" type="hidden"/>
                <fieldset>
                    <legend>微信群发消息</legend>
                    <div class="ui-form-item">
                        <label for="" class="ui-label">
                            <span class="ui-form-required">*</span>标题
                        </label>
                        <input class="ui-input" name="title" type="text"> <span class="ui-form-other"></span>
                        <p class="ui-form-explain">标题不能为空且长度不能超过64字。</p>
                    </div>
                    <div class="ui-form-item">
                        <label for="" class="ui-label"> 作者（选填） </label>
                        <input class="ui-input" type="text" name="author"> <span class="ui-form-other"></span>
                        <p class="ui-form-explain">作者不能超过8个字。</p>
                    </div>
                    <div class="ui-form-item">
                        <label for="" class="ui-label"> 摘要（选填） </label>
                        <input class="ui-input " id="t_w_350" type="text" name="digest"> <span class="ui-form-other"></span>
                        <p class="ui-form-explain">摘要不能超过30个字。</p>
                    </div>
                 
                    <div class="ui-form-item">
                        <label for="" class="ui-label">粉丝分组</label>
                        <select id="fans_group" name="fans_group">
                        </select> 
                    </div>
					   <?php if($ac_type==1):?>
                    <?php endif;?>
                    <div class="ui-form-item">
                        <label class="ui-label"> <span class="ui-form-required">*</span>封面 </label>
                        <input type="file" name="image" id="uploadImage" onchange="PreviewImage();"/>
                        <p class="ui-form-explain">大图片建议尺寸：900像素 * 500像素</p>
                    </div>
                    <div class="ui-form-item">
                        <label class="ui-label">添加原文链接 </label>
                        <input class="ui-input " id="t_w_350" type="text" name="source_url"/>
                        <p class="ui-form-explain"></p>
                    </div>
                    <div class="ui-form-item">
                        <label for="" class="ui-label"> <span class="ui-form-required">*</span>正文 </label>
                        <textarea id="content" name="content"></textarea>
                        <p class="ui-form-explain">不能为空且长度不能超过20000字</p>
                    </div>
                    <div class="ui-form-item">
<!--                        <input id="content" name="content" type="hidden"/>-->
                        <input id="btn_submit" type="button" class="ui-button ui-button-lorange btn_primary" value="保存">
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
    <iframe src="about:blank" style="display: none;" id="hideFrame" name="hideFrame" frameborder="0"></iframe>
   <script type="text/javascript" charset="utf-8" src="http://www.12301.cc/ue_126/ueditor_config_mini_wei.js"></script>
      <!-- 核心文件 -->
      <script type="text/javascript" src="http://www.12301.cc/ue_126/ueditor.all.min.js"></script>
   <script>
      $(document).ready(function () {
         var ue = UE.getEditor('content');
            
        var ac_type = $("input[name=ac_type]").val();
        //if (ac_type==1) {
            //服务号获取分组
            $.getJSON('<?=$domain?>module/wechat/ichat.php', {
                action:'GetWxGrpList',
                hash:$('input[name=hash]').val()
            }).done(function(json){
                var options = '<option value="-1">--选择分组--</option>';
                for(var i in json) {
                    options += '<option value="'+json[i]['id']+'">'+json[i]['name']+'('+json[i]['count']+')</option>';
                }
                $("#fans_group").html(options);
            });
       // }
            
        $("#btn_submit").on('click', function(){
            var txt_content = ue.getContent();
            $("#content").val(txt_content);
//            console.log(txt_content);return;
            if ($('input[name=title]').val()=='') {
                alert('标题不能为空');return false;
            }

            $("#frm").submit();
        });
      });
   </script>
<?php include('common/footer.html')?>